package database

import (
	"log"
	"myNote/models"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

var DB *gorm.DB

func init() {
	var err error
	DB, err = gorm.Open("mysql", "root:woai1234@/mynotes?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		log.Fatal("初始化数据库失败")
	} else {
		DB.AutoMigrate(models.Article{}, models.User{}, models.Session{})
	}
}